//#include <iostream>
#include <climits>
using namespace std;

class Point
{
public:
	int x;
	int y;
};

class PaperLine
{
public:
	Point* data;
	int Size;

	PaperLine(int n) : _n(n)
	{
		_perPixel = 1;

		if(n < 0) n = 0;
		_size = 1;
		for(int i = 0; i < n - 1; i++)
			_size *= 2;

		_size += 1;

		Size = _size;	//外部接口

		data = new Point[_size];

		calc(_size);
	}

	~PaperLine()
	{
		delete [] data;
	}

	void Move(int x, int y)
	{
		Move(x, y, 0, _size);
	}
	void FixPosition(int w, int h)
	{
		int PerPixel;
		int top = INT_MAX, left = INT_MAX, buttom = INT_MIN, right = INT_MIN;

		for(int i = 0; i < _size; i++)
		{
			if(data[i].y < top) top = data[i].y;
			if(data[i].x < left) left = data[i].x;

			if(data[i].y > buttom) buttom = data[i].y;
			if(data[i].x > right) right = data[i].y;
		}
/*
		int dif;
		if(buttom - top == right - left && right - left == 0) PerPixel = 1;
		else
		{
			if(buttom - top > right - left)
				PerPixel = h / (buttom - top);
			else PerPixel = w / (right - left);
		}
		// Rote(left - right, top - buttom);
*/

		if((double)(buttom - top) / (double)(right - left) > (double)h / (double)w)
		{
			if(buttom - top > 0) PerPixel = h / (buttom - top);
			else PerPixel = h;
		}
		else
		{
			if(right - left > 0) PerPixel = w / (right - left);
			else PerPixel = w;
		}

		if (PerPixel < 1) PerPixel = 1;

		Move(left, top);

		ResizeData(PerPixel);
	}
private:
	int _n;
	// Point* _datas;
	int _size;
	int _perPixel;

	void Move(int x, int y, int begin, int end)
	{
		for(int i = begin; i < end; i++)
		{
			data[i].x -= x;
			data[i].y -= y;
		}
	}

	void calc(int n)
	{
		// 边界条件
		if(n <= 2)
		{
			//横线
			data[0].x = 1;
			data[0].y = 0;

			data[1].x = 0;
			data[1].y = 0;

			return;
		}

		int h = n / 2 + 1;

		// 分别计算两部分
		calc(h);

		// 旋转第二部分
		for(int i = n / 2 + 1; i < n; i++)
		{
			int p = n - i - 1;
			data[i].x = data[p].y;
			data[i].y = - data[p].x;
		}

		// 平移使终点在0, 0
		Move(data[n - 1].x, data[n - 1].y, 0, n);
	}

	void print(int n)
	{
		//for(int i = 0; i < n; i++)
		//	cout << a[i].x << " " << a[i].y << endl;
	}
	void ResizeData(int per)
	{
		// clean before resize
		for(int i = 0; i < _size; i++)
		{
			data[i].x /= _perPixel;
			data[i].y /= _perPixel;
		}

		// calc new size
		for(int i = 0; i < _size; i++)
		{
			data[i].x *= per;
			data[i].y *= per;
		}

		_perPixel = per;
	}
};